/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.uniminuto.park.controlador;

import co.uniminuto.park.clases.Estacionamiento;
import co.uniminuto.park.clases.Geolocalizacion;
import co.uniminuto.park.clases.Roles;
import co.uniminuto.park.clases.Usuario;

import co.uniminuto.park.dao.loginDao;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;
import org.bson.types.ObjectId;
import org.primefaces.context.RequestContext;
import org.primefaces.event.RowEditEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

/**
 *
 * @author Esteban Rozo
 */
@ManagedBean
@ViewScoped
public class validarPagina {
private Usuario user;

FacesContext context = FacesContext.getCurrentInstance();
    public Usuario getUser() {
        return user;
    }

    public void setUser(Usuario user) {
        this.user = user;
    }

   

    
    private EstacionamientosLista getElementoApplication() {
        FacesContext cont = FacesContext.getCurrentInstance();
        return cont.getApplication().evaluateExpressionGet(cont, "#{elementoApplication}", EstacionamientosLista.class);
    }

    public validarPagina() {
        
        
        user= new Usuario();
         HttpSession httpSession = (HttpSession) context.getExternalContext().getSession(true);
    //httpSession.setAttribute("user", user);
        user=(Usuario) httpSession.getAttribute("user");
    }

   
  
    public void login(ActionEvent actionEvent) {  
        RequestContext context = RequestContext.getCurrentInstance();  
        FacesMessage msg = null;  
        boolean loggedIn = false;  
        loginDao login= new loginDao();
        if(login.getLoginUs(user) ) {  
            loggedIn = true;  
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Bienvenido", user.getCorreo());  
        } else {  
            loggedIn = false;  
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Error de Login", "Credenciales Invalidas");  
        }  
          
        FacesContext.getCurrentInstance().addMessage(null, msg);  
        context.addCallbackParam("loggedIn", loggedIn);  
    }  

  
        
    
}
